package until;

import com.alibaba.fastjson.JSON;
import com.alibaba.fastjson.JSONArray;
import com.alibaba.fastjson.JSONObject;

public class Test {
    public static void main(String[] args) {
        String jsonString = "{\"totalPrice\":4787,\"name\":[\"iPhone 15 Pro Max\",\"vivo s17\"],\"num\":[1,1],\"address\":\"666\"}";

        // 使用 FastJSON 解析 JSON 字符串
        JSONObject jsonObject = JSON.parseObject(jsonString);

        // 提取四项数据
        int totalPrice = jsonObject.getIntValue("totalPrice");
        String address = jsonObject.getString("address");
        JSONArray nameArray = jsonObject.getJSONArray("name");
        JSONArray numArray = jsonObject.getJSONArray("num");

        // 输出结果
        System.out.println("Total Price: " + totalPrice);
        System.out.println("Address: " + address);

        // 输出商品名称和数量
        for (int i = 0; i < nameArray.size(); i++) {
            String name = nameArray.getString(i);
            int num = numArray.getIntValue(i);
            System.out.println("Item " + (i + 1) + ": " + name + " (Quantity: " + num + ")");
        }
    }
}